aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/groups/[groupId]/edit
diff options
context:
space:
mode:
authorSebastien Castiel <sebastien@castiel.me>2023-12-05 17:39:05 -0500
committerSebastien Castiel <sebastien@castiel.me>2023-12-05 17:39:05 -0500
commited55c696cd083bfaa5429082a9c5edd4ebde0cd8 (patch)
tree9f387881f85716bcb4a05d6fce13bfe59fbc9c17 /src/app/groups/[groupId]/edit
parent1fd6e48807d455f66d9cd79db64cbf9e9f947c6c (diff)
First version
Diffstat (limited to 'src/app/groups/[groupId]/edit')
-rw-r--r--src/app/groups/[groupId]/edit/page.tsx36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/app/groups/[groupId]/edit/page.tsx b/src/app/groups/[groupId]/edit/page.tsx
new file mode 100644
index 0000000..23bd865
--- /dev/null
+++ b/src/app/groups/[groupId]/edit/page.tsx
@@ -0,0 +1,36 @@
+import { GroupForm } from '@/components/group-form'
+import { Button } from '@/components/ui/button'
+import { getGroup, updateGroup } from '@/lib/api'
+import { groupFormSchema } from '@/lib/schemas'
+import { ChevronLeft } from 'lucide-react'
+import Link from 'next/link'
+import { notFound, redirect } from 'next/navigation'
+
+export default async function EditGroupPage({
+ params: { groupId },
+}: {
+ params: { groupId: string }
+}) {
+ const group = await getGroup(groupId)
+ if (!group) notFound()
+
+ async function updateGroupAction(values: unknown) {
+ 'use server'
+ const groupFormValues = groupFormSchema.parse(values)
+ const group = await updateGroup(groupId, groupFormValues)
+ redirect(`/groups/${group.id}`)
+ }
+
+ return (
+ <main>
+ <div className="mb-4">
+ <Button variant="ghost" asChild>
+ <Link href={`/groups/${groupId}`}>
+ <ChevronLeft className="w-4 h-4 mr-2" /> Back to group
+ </Link>
+ </Button>
+ </div>
+ <GroupForm group={group} onSubmit={updateGroupAction} />
+ </main>
+ )
+}